package com.ruoyi.project.business.controller;

import java.util.List;

import com.ruoyi.project.business.domain.BusinessArea;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.service.IBusinessAreaService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 租地土地Controller
 * 
 * @author ruoyi
 * @date 2020-10-19
 */
@RestController
@RequestMapping("/business/area")
public class BusinessAreaController extends BaseController
{
    @Autowired
    private IBusinessAreaService businessAreaService;

    /**
     * 查询租地土地列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessArea businessArea)
    {
        startPage();
        List<BusinessArea> list = businessAreaService.selectBusinessAreaList(businessArea);
        return getDataTable(list);
    }

    /**
     * 导出租地土地列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:export')")
    @Log(title = "租地土地", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessArea businessArea)
    {
        List<BusinessArea> list = businessAreaService.selectBusinessAreaList(businessArea);
        ExcelUtil<BusinessArea> util = new ExcelUtil<BusinessArea>(BusinessArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取租地土地详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessAreaService.selectBusinessAreaById(id));
    }

    /**
     * 新增租地土地
     */
    @PreAuthorize("@ss.hasPermi('business:area:add')")
    @Log(title = "租地土地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessArea businessArea)
    {

        return toAjax(businessAreaService.insertBusinessArea(businessArea));
    }

    /**
     * 修改租地土地
     */
    @PreAuthorize("@ss.hasPermi('business:area:edit')")
    @Log(title = "租地土地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessArea businessArea)
    {
        return toAjax(businessAreaService.updateBusinessArea(businessArea));
    }

    /**
     * 删除租地土地
     */
    @PreAuthorize("@ss.hasPermi('business:area:remove')")
    @Log(title = "租地土地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessAreaService.deleteBusinessAreaByIds(ids));
    }
}
